package com.kikyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kikyou.pojo.Cities;
import com.kikyou.mapper.CitiesMapper;
import com.kikyou.pojo.Province;
import com.kikyou.service.ICitiesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuankaiqiang
 * @since 2022-03-09
 */
@Service
public class CitiesServiceImpl extends ServiceImpl<CitiesMapper, Cities> implements ICitiesService {
@Autowired
private CitiesMapper citiesMapper;
@Autowired
private RedisTemplate redisTemplate;
    /**
     * Description : TODO 查询公司有业务城市 <br/>
     * ChangeLog : 1. 创建 (2022/3/9 20:15 [ykq11]);
     * *
     * @return java.util.List<com.kikyou.pojo.Province>
     **/
    @Override
    public List<Cities> findHotCites() {
        ListOperations listOperations = redisTemplate.opsForList();
        List<Cities> cities =  listOperations.range("hotcities", 0, -1);
        if(CollectionUtils.isEmpty(cities)){
            cities =citiesMapper.selectList(new QueryWrapper<Cities>()
                    .eq("cityid","510100")
                    .or().eq("cityid","330100")
                    .or().eq("cityid","110000")
                    .or().eq("cityid","120000")
                    .or().eq("cityid","310000")
                    .or().eq("cityid","500000"));
                     listOperations.rightPushAll("hotcities",cities);
            return  cities;
        }
        return cities;
    }
}
